#set($layout = "blank.html")
<link rel="stylesheet" href="$!{base}/resources/assets/css/chosen.css" />
<div class="space-4"></div>
<div class="row">
	<div class="col-xs-1"></div>
	<div class="col-xs-10">
		<form id="addProjectForm">
			<div>
				<label> 分支机构 <small class="text-info">项目所属分支机构</small></label>
				<div>
					<select class="chosen-select form-control" name="subsidiaryId" id="subsidiaryId" data-placeholder="请选择分支机构">
						<option value="0">请选择分支机构</option> #foreach($subsidiary in $obj.data.subsidiaries)
						<!-- 全部用户 -->
						<option value="$!{subsidiary.id}" #if($!subsidiary.id == $!obj.data.project.s_id)selected #end>$subsidiary.name $!subsidiary.code</option>
						<!-- 遍历结束 --> #end
					</select>
				</div>
			</div>
			
			<div>
				<label> 项目名称 <small class="text-info">分支项目名称</small></label>
				<div>
					<input class="form-control" type="text" placeholder="请输入项目名称" name="name" value="$!obj.data.project.p_name" data-type='required' data-error='请输入项目名称'>
				</div>
			</div>

			<div>
				<label> 项目地址 <small class="text-info">项目部地址</small></label>
				<div>
					<input class="form-control" value="$!obj.data.project.p_address" type="text" placeholder="请输入项目地址" name="address" data-type='required' data-error='请输入项目地址'>
				</div>
			</div>

			<div>
				<label> 项目编码 <small class="text-info">分支项目编码</small></label>
				<div>
					<input class="form-control" type="text" placeholder="请输入项目编码" name="code" value="$!obj.data.project.p_code" data-type='required' data-error='请输入项目编码'>
				</div>
			</div>

			<div>
				<label> 项目电话 <small class="text-info">分支项目联系方式</small></label>
				<div>
					<input class="form-control" type="text" placeholder="请输入项目联系方式" name="phone" value="$!obj.data.project.p_phone" data-type='phone' data-error='请输入项目联系方式'>
				</div>
			</div>

			<div>
				<label> 项目负责人 <small class="text-info">项目负责人</small></label>
				<div>
					<select class="chosen-select form-control" name="principalId" id="principalId" data-placeholder="请选择项目负责人">
						<option value="0">请选择选项目负责人</option> #foreach($user in $obj.data.users)
						<!-- 全部用户 -->
						<option value="$!{user.id}" #if($user.id== $!obj.data.project.u_id )selected #end>$user.realName $!user.name</option>
						<!-- 遍历结束 --> #end
					</select>
				</div>
			</div>

			<div>
				<label> 项目介绍 <small class="text-info">项目介绍信息</small></label>
				<div>
					<textarea class="form-control limited autosize-transition" name="description" maxlength="500" placeholder="请输入项目描述信息">$!obj.data.project.p_des</textarea>
				</div>
			</div>

			<div class="space-4"></div>
			<div class="space-4"></div>
			<input type="hidden" name="id" id="projectId" value="$!obj.data.project.id">
			<div class="pull-right" style="margin-right:45px">
				<button type="button" class="btn btn-sm btn-primary" onclick="save()">
					<i class="fa fa-save"></i> 提交
				</button>
				<button class="btn btn-sm btn-warning btn-dialog-undo">
					<i class="fa fa-undo"></i> 返回
				</button>
			</div>
		</form>
	</div>
	<div class="col-xs-1"></div>
</div>
<script src="$!{base}/resources/assets/js/jquery.inputlimiter.1.3.1.js"></script>
<script src="$!{base}/resources/assets/js/jquery.autosize.js"></script>
<script src="$!{base}/resources/assets/js/chosen.jquery.js"></script>
<script>
	$(function() {
		//描述框效果
		$('textarea.limited').inputlimiter({
			remText : '还可以输入 %n 字',
			limitText : '最大允许: %n 字.'
		});
		$('textarea[class*=autosize]').autosize({
			append : "\n"
		});

		//chosen
		$('.chosen-select').chosen();
	})

	function save() {
		if ($('input').validation()) {
			if ($("#subsidiaryId").val() == 0) {
				validationFail("请选择分支机构", $("#subsidiaryId").parent());
				return;
			}
			if ($("#principalId").val() == 0) {
				validationFail("请选择机构负责人", $("#principalId").parent());
				return;
			}
			if ($('#projectId').val()) {
				$.post(getRootPath() + '/project/edit', $('#addProjectForm').serialize(), commonAjaxCallBasck, 'json');
			} else {
				$.post(getRootPath() + '/project/add', $('#addProjectForm').serialize(), commonAjaxCallBasck, 'json');
			}

		}
	}
</script>